package cn.lee.share;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JTextArea;

import cn.lee.share.http.HttpServer;
import cn.lee.share.utils.LogUtils;

public class KindleShareFrame {
    JButton start ;
    JButton stop ;
    JTextArea textArea;
    HttpServer server;
    public KindleShareFrame(){
         start = new JButton("start");
         stop = new JButton("stop");
         textArea = new JTextArea();
         textArea.setRows(4);
         textArea.setColumns(10);
         LogUtils log = LogUtils.getInstance();
         log.setTextArea(textArea);
         start.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
                     server = new HttpServer();
                     Thread t = new Thread(server);
                     t.start();
              }
         });
         stop.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
                     server.shutDown();
              }
         });
    }
    public void actionPerformed(ActionEvent e){
        if(e.getSource().equals(start)){
            server = new HttpServer();
            server.await();
        }else if(e.getSource().equals(stop)){
            server.shutDown();
        }
     }

    public JButton getStart() {
        return start;
    }

    public JButton getStop() {
        return stop;
    }
    public JTextArea getTextArea() {
        return textArea;
    }
    
    
}
